# import customtkinter as ctk

# # 设置默认的颜色主题和模式
# ctk.set_appearance_mode("system")  # Modes: system (default), light, dark
# ctk.set_default_color_theme("blue")  # Themes: blue (default), dark-blue, green

# # 创建主窗口
# app = ctk.CTk()

# # 设置窗口标题
# app.title("我的第一个CustomTkinter应用")

# # 设置窗口大小
# app.geometry("800x600")
# bg_color = app.cget("fg_color")
# # 添加一个标签
# label = ctk.CTkLabel(master=app, text="欢迎使用CustomTkinter!")
# label.pack(pady=20, padx=10)


# frame = ctk.CTkFrame(master=app, width=200, height=150, corner_radius=10, fg_color=bg_color,border_color="black",border_width=2)
# # 放置到窗口中
# frame.pack(padx=20, pady=20)


# # 添加一个按钮，并绑定点击事件
# def button_click():
#     label.configure(text="按钮被点击了!")

# button = ctk.CTkButton(master=frame, text="点击我", command=button_click)
# button.pack(pady=20, padx=10)

# # 运行应用
# app.mainloop()



import customtkinter as ctk

# 设置主题
ctk.set_appearance_mode("system")
ctk.set_default_color_theme("blue")

# 创建主窗口，并隐藏系统标题栏
app = ctk.CTk()
app.overrideredirect(True)  # 隐藏默认标题栏
app.geometry("800x600")
app.title("自定义顶部工具栏")

# 自定义标题栏高度
TITLE_BAR_HEIGHT = 30

# 自定义标题栏 Frame
title_bar = ctk.CTkFrame(app, height=TITLE_BAR_HEIGHT, corner_radius=0,fg_color="gray20")
title_bar.pack(fill="x")

# 左侧：下拉菜单和按钮
combo_frame = ctk.CTkFrame(title_bar, corner_radius=0,fg_color="transparent")
combo_frame.pack(side="left", padx=5)

combo = ctk.CTkComboBox(combo_frame,  corner_radius=0,values=["选项1", "选项2", "选项3"])
combo.pack(side="left", padx=2)

btn = ctk.CTkButton(combo_frame, text="按钮", width=60, corner_radius=0, command=lambda: print("按钮点击"))
btn.pack(side="left", padx=2)

# 右侧：最小化、最大化、关闭按钮
button_frame = ctk.CTkFrame(title_bar, corner_radius=0, fg_color="transparent")
button_frame.pack(side="right", padx=5)

# 最小化按钮
minimize_btn = ctk.CTkButton(button_frame, text="—", width=30, corner_radius=0, height=TITLE_BAR_HEIGHT - 5,
                             fg_color="gray", hover_color="dark gray", command=app.iconify)
minimize_btn.pack(side="left", padx=2)

# 最大化按钮
maximize_btn = ctk.CTkButton(button_frame, text="□", width=30, corner_radius=0, height=TITLE_BAR_HEIGHT - 5,
                             fg_color="gray", hover_color="dark gray", command=lambda: toggle_maximize())
maximize_btn.pack(side="left", padx=2)

# 关闭按钮
close_btn = ctk.CTkButton(button_frame, text="✕", width=30, corner_radius=0, height=TITLE_BAR_HEIGHT - 5,
                          fg_color="red", hover_color="dark red", command=app.destroy)
close_btn.pack(side="left", padx=2)

# 窗口拖动功能（模拟标题栏拖动）
def move_window(event):
    app.geometry(f"+{event.x_root - offset_x}+{event.y_root - offset_y}")

def get_offset(event):
    global offset_x, offset_y
    offset_x = event.x_root - app.winfo_x()
    offset_y = event.y_root - app.winfo_y()

title_bar.bind("<Button-1>", get_offset)
title_bar.bind("<B1-Motion>", move_window)

# 切换最大化状态
def toggle_maximize():
    if app.attributes("-zoomed"):
        app.attributes("-zoomed", False)
        app.geometry("800x600")
    else:
        app.attributes("-zoomed", True)

# 主窗口内容区域
content_frame = ctk.CTkFrame(app)
content_frame.pack(fill="both", expand=True)

label = ctk.CTkLabel(content_frame, text="这里是主窗口内容区域", font=("Arial", 16))
label.pack(pady=20)

app.mainloop()